package com.blog.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.blog.entity.ProductType;
import com.blog.dao.ProductTypeDao;
import com.blog.service.ProductTypeService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mars123
 * @since 2019-07-02
 */
@Service
public class ProductTypeServiceImpl implements ProductTypeService {


    @Override
    public Page<ProductType> index(ProductType param, Page<ProductType> page) {
        return new ProductType().selectPage(page, new EntityWrapper<ProductType>().orderBy("product_type.`order`"));
    }

    @Override
    public ProductType create(ProductType product) {
        product.setStatus(1);
        if (product.insert()) {
            return product;
        }
        return null;
    }

    @Override
    public ProductType update(ProductType product) {
        if (product.updateById()) {
            return product;
        }
        return null;
    }

    @Override
    public boolean delete(int id) {
        return new ProductType().deleteById(id);
    }

    @Override
    public ProductType view(int id) {
        return new ProductType().selectById(id);
    }

    @Override
    public List<ProductType> getTypes() {
        return new ProductType().selectAll();
    }


}
